﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;

namespace ExpenseTracker.Entity
{
    public class Configuration
    {
        private static object _synclock = new object();
        private static ExpenseTracker.Entity.Configuration _configuration;

        public string ApplicationName { get; set; }
        public int Year { get; set; }
        public string Province { get; set; }
        public float GSTRate { get; set; }
        public float PSTRate { get; set; }
        public string DatabaseFileExtension { get; set; }

        private Configuration() { }

        public static ExpenseTracker.Entity.Configuration Instance
        {
            get
            {
                lock (_synclock)
                {
                    if (_configuration == null)
                    {
                        _configuration = new Configuration();
                        _configuration.ApplicationName = ConfigurationManager.AppSettings["ApplicationName"];
                        _configuration.Year = int.Parse(ConfigurationManager.AppSettings["Year"]);
                        _configuration.Province = ConfigurationManager.AppSettings["Province"];
                        _configuration.GSTRate = float.Parse(ConfigurationManager.AppSettings["GSTRate"]);
                        _configuration.PSTRate = float.Parse(ConfigurationManager.AppSettings["PSTRate"]);
                        _configuration.DatabaseFileExtension = ConfigurationManager.AppSettings["DatabaseFileExtension"];
                    }
                    return _configuration;
                }
            }
        }
    }
}
